import Cookies from 'js-cookie'
import SettingEnv from '@/setting.env'
import { mapState, mapActions, mapMutations,mapGetters } from "vuex";
// import store from '../store';
const TokenKey = 'vue_admin_template_token'
const ActivitiesId = 'vue_admin_activities_id'
const routeId = 'vue_admin_route_id'

/**
 * 获取cookies
 * @returns {*}
 */
export function getToken(name) {
  return Cookies.get(name || TokenKey)
}

/**
 * 拿到 cookie 值
 * @param name  名称
 * @returns {*}
 */
export function getCookies(name = 'default') {
  return Cookies.get(`admin-${name}`)
}

/**
 * 拿到 cookie 全部的值
 * @returns {*}
 */
export function getCookiesAll() {
  return Cookies.get()
}

/**
 * 存储 cookie 值
 * @param name  名称
 * @param value 值
 * @param cookieSetting
 */
export function setCookies(name, value = '', cookieSetting = {}) {
  Object.assign(cookieSetting, {
    expires: SettingEnv.cookiesExpires
  })
  Cookies.set(`admin-${name}`, value, cookieSetting)
}

/**
 * 存入cookies
 * @param token
 * @returns {*}
 */
export function setToken(token) {
  return Cookies.set(TokenKey, token, {
    expires: SettingEnv.cookiesExpires
  })
}

/**
 * 删除cookies
 * @returns {*}
 */
export function removeToken(name) {
  return Cookies.remove(name ? `admin-${name}` : TokenKey)
}

/**
 * 获取路由的活动id
 * @returns {id}
 */
export function setActivitiesId(Activities) {
  return Cookies.set(ActivitiesId, Activities, {
    expires: SettingEnv.cookiesExpires
  });
}
/**
 * 获取的活动管理id
 * @returns {id}
 */
export function setRouteId(routeid) {
  return Cookies.set(routeId, routeid, {
    expires: SettingEnv.cookiesExpires
  });
}

/**
 * 拿到活动管理id
 * @returns {*}
 */
export function getRouteId() {
  return Cookies.get(routeId)
}

/**
 * 删除活动管理id
 * @returns {*}
 */
export function removeRouteId(routeId) {
  return Cookies.remove(routeId)
}